<?php
class Validation{
	public function isEmail($value,$min=NULL,$max=NULL)
	{
		if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}


	public function isAlpha($value,$min=NULL,$max=NULL)
	{
		if (preg_match('/^[a-zA-Z]+$/', $value))
		{

			return $this->isLong($value,$min,$max);
		}
		return false;
	}
	public function isAlphaNum($value,$min=NULL,$max=NULL)
	{
		if (preg_match("/^[A-Za-z0-9 ]+$/", $value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}
	public function isDate($value,$min=NULL,$max=NULL)
	{
		if(preg_match("/^[0-9]{4}(\-|\/)[0-9]{1,2}(\\1)[0-9]{1,2}(|\s+[0-9]{1,2}(|:[0-9]{1,2}(|:[0-9]{1,2})))$/",$value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}
	public function isUrl($value,$min=NULL,$max=NULL)
	{
		if(preg_match("/^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/i", $value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}
	public function isIP($value,$min=NULL,$max=NULL)
	{
		if (preg_match("/^(2[0-5]{2}|1[0-9]{2}|[1-9][0-9]|0)\.(2[0-5]{2}|1[0-9]{2}|[1-9][0-9]|0)\.(2[0-5]{2}|1[0-9]{2}|[1-9][0-9]|0)\.(2[0-5]{2}|1[0-9]{2}|[1-9][0-9]|0)$/i", $value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}

	public function isEmpty($value,$min=NULL,$max=NULL)
	{
		if (strlen($value) < 1 || is_null($value)) {
			return $this->isLong($value,$min,$max);
		}
		return false;
	}

	public function isNum($value,$min=NULL,$max=NULL)
	{
		if (is_numeric($value))
		{
			return $this->isLong($value,$min,$max);
		}
		return false;
	}
	public function isLong($value ,$min=NULL,$max=NULL) {
		if(($min!==NULL && $max===NULL) && strlen($value)<$min){
			return false;
		}
		if(($min===NULL && $max!==NULL) && strlen($value)>$max){
			return false;
		}
		if(($min!==NULL && $max!==NULL) && (strlen($value)<$min || strlen($value)>$max)){
			return false;
		}
		return true;
	}
}
?>